const Sequelize = require('sequelize');
let db = require('../../config/lib/db');
const User = require('./User');


let Picture = db.define('picture', {
    id: {
        filed: 'id',
        primaryKey: true,
        type: Sequelize.BIGINT,
        autoIncrement: true,
        allowNull: false
    },
    label: {
        field: 'label',
        type: Sequelize.STRING,
        allowNull: false
    },
    address: {
        field: 'address',
        type: Sequelize.STRING,
        allowNull: false
    },
    file_type: { // image css js html
        field: 'file_type',
        type: Sequelize.STRING,
        allowNull: false,
        defaultValue: 'image'
    },
    is_deleted: { // 0显示 1删除
        field: 'is_deleted',
        type: Sequelize.TINYINT,
        defaultValue: 0,
        allowNull: false
    },
    user_id: {
        field: 'user_id',
        type: Sequelize.BIGINT,
        allowNull: false
    }
},{
    tableName: 't_pic',
    timestamps: true,
    createdAt: 'created_at',
    updatedAt: 'updated_at',
    // 锁定表名，!+s
    freezeTableName: true,
    charset: 'utf8mb4',
    collate: 'utf8mb4_general_ci'
});

Picture.belongsTo(User, {as: 'user', foreignKey: 'user_id', targetKey: 'id', constraints: false})

Picture.sync({ force: false, alter: false});

module.exports = Picture;
